{extend name='admin'/}
{block name='css'}
<link href="{:asset('HHuploadify-master/dist/HHuploadify.css')}" rel="stylesheet" type="text/css" >
<script src="{:asset('HHuploadify-master/dist/HHuploadify.js')}" type="text/javascript" ></script>
{/block}
{block name='content'}
<div class="container-fluid">
    <div class="page-title">
        <h1>我的个人资料</h1>
    </div>
    <form action="#" method="post" class="form-horizontal">
        <input type="hidden" name="id" value="{$data.0.id}">
        <div class="form-group">
            <label class="col-sm-3 control-label">头像</label>
            <div class="col-sm-6" id="goodslogo">
            </div>
            <input type="hidden" name="mylogo" id="goods_logo"/>
        </div>
        <div class="form-group">
            <label for="text" class="col-sm-3 control-label">用户名</label>
            <div class="col-sm-6">
                <input  class="form-control" name="username" type="type" value="{$data.0.username}" placeholder="用户名" readonly>
                <p class="help-block">用户名不允许修改</p>
            </div>
        </div>
        <div class="form-group">
            <label for="nickname" class="col-sm-3 control-label">昵称</label>
            <div class="col-sm-6">
                <input id="nickname" class="form-control" name="nickname" type="type" value="{$data.0.nickname}" placeholder="昵称">
                <p class="help-block">限制在 2-16 个字符</p>
            </div>
        </div>
        <div class="form-group">
            <label for="bio" class="col-sm-3 control-label">简介</label>
            <div class="col-sm-6">
                <textarea id="bio" class="form-control" name="content" placeholder="Bio" cols="30" rows="6">{$data.0.content}</textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-6">
                <input class="btn btn-primary" value="更新" type="submit">
                <a class="btn btn-link" id="post" href="#">修改密码</a>
            </div>
        </div>
    </form>
</div>
{/block}
{block name='js'}
<script>
    $(function(){
        new HHuploadify({
            container:'#goodslogo',
            single:true,
            chooseText:'选取图片',
            auto:true,
            url:"{:url('admin/index/update')}",
            field:'mylogo',
            //上传成功后的回调函数
            onUploadSuccess:function(file,data){
                var obj =JSON.parse(data);
                if(obj.status=='success'){
                    $('#goods_logo').val(obj.logo);
                }else{
                    layer.msg('上传图片失败',{icon:5,time:1000});
                }
            },
            onRemoved:function(){
                $('#goods_logo').val('');
            }
        });
        $('#post').click(function(){
            layer.ready(function(){
                layer.open({
                    type:2,
                    title:'修改密码',
                    maxmin:true,
                    area:['1000px','300px'],
                    content:"{:url('admin/index/post')}"
                });
            });
        });
        $('.form-horizontal').submit(function(evt){
            //禁止表单提交
            evt.preventDefault();
            var shuju =$(this).serialize();
            $.ajax({
                url:"{:url('admin/index/personal')}",
                data:shuju,
                type:'post',
                dateType:'json',
                success:function(msg){
                    if(msg==1){
                        layer.alert('更新成功',{icon:6},function(){
                            parent.location.reload();
                        })
                    }else{
                        layer.alert('更新失败',{icon:5})
                    }
                }
            })


        })
    })
</script>
{/block}